home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Shareware / Programare / sharp / wwwSharp_setup.exe / {app} / Examples / TreeView / Assembly / TreeView.cs next >
Text File  |  2003-12-04  |  2KB  |  92 lines

  1. using System.Reflection;
  2. using System;
  3. using System.Windows.Forms;
  4. using mshtml;
  5.  
  6. [assembly: AssemblyTitle("")]
  7. [assembly: AssemblyDescription("")]
  8. [assembly: AssemblyConfiguration("")]
  9. [assembly: AssemblyCompany("")]
  10. [assembly: AssemblyProduct("")]
  11. [assembly: AssemblyCopyright("")]
  12. [assembly: AssemblyTrademark("")]
  13. [assembly: AssemblyCulture("")]
  14. [assembly: AssemblyVersion("1.0.0.0")]
  15. [assembly: AssemblyKeyFile("")]
  16.  
  17. namespace wwwSharp.ClrHost.Examples
  18. {
  19.     public class TreeView: System.Windows.Forms.TreeView
  20.     {
  21.         public TreeView(): base()
  22.         {
  23.         }
  24.  
  25.         private IHTMLElement m_OutputControl = null;
  26.         
  27.         public IHTMLElement OutputControl
  28.         {
  29.             get {return m_OutputControl;}
  30.             set {m_OutputControl = value;}
  31.         }
  32.  
  33.         public void FillTreeView()
  34.         {
  35.             // Display a wait cursor while the TreeNodes are being created.
  36.             Cursor.Current = Cursors.WaitCursor;
  37.  
  38.             // Suppress repainting the TreeView until all the objects have been created.
  39.             BeginUpdate();
  40.             try
  41.             {
  42.                 // Clear the TreeView each time the method is called.
  43.                 Nodes.Clear();
  44.  
  45.                 // Add 1000 nodes to the tree.
  46.                 for (int i = 1; i <= 10; i++)
  47.                 {
  48.                     TreeNode node = Nodes.Add("Node " + i.ToString());
  49.                     for (int j = 1; j <= 10; j++)
  50.                     {
  51.                         TreeNode child = node.Nodes.Add("Child " + j.ToString());
  52.                         for (int k = 1; k <= 10; k++)
  53.                             child.Nodes.Add("Subchild " + k.ToString());
  54.                     }
  55.                 }
  56.             }
  57.             finally
  58.             {
  59.                 // Reset the cursor to the default for all controls.
  60.                 Cursor.Current = Cursors.Default;
  61.  
  62.                 // Begin repainting the TreeView.
  63.                 EndUpdate();
  64.             }
  65.         }
  66.  
  67.         protected override void OnAfterSelect(TreeViewEventArgs e)
  68.         {
  69.             base.OnAfterSelect(e);
  70.  
  71.             //Send output to HTML control.
  72.             if (m_OutputControl != null)
  73.             {
  74.                 if (e.Node != null)
  75.                 {
  76.                     string strFullNodeName = e.Node.Text;
  77.                     TreeNode node = e.Node.Parent;
  78.                     while (node != null)
  79.                     {
  80.                         strFullNodeName = node.Text + "/" + strFullNodeName;
  81.                         node = node.Parent;
  82.                     }
  83.  
  84.                     m_OutputControl.innerText = "Selected node: " + strFullNodeName;
  85.                 }
  86.                 else
  87.                     m_OutputControl.innerText = "";
  88.             }
  89.         }
  90.     }
  91. }
  92.